#ifndef CACHE_H
#define CACHE_H

#include<iostream>
#include<vector>
#include<iomanip>
#include<fstream>
#include<sstream>
#include<algorithm>
using namespace std;

#define addr pair<unsigned, unsigned>

class Cache{
private:
    unsigned size, associativity, blockSize;    // 缓存大小,关联度,块大小                            
    bool replace_policy, write_policy;    // 表示替换策略和写策略                                
    string trace_file;      // 用于存储追踪文件的路径   

    // 用于统计缓存操作的变量                                              
    unsigned totalReads, missReads, totalWrites, missWrites, writeBack; 
    
    // 表示缓存中的一个块
    struct Block {
        unsigned countBlock, tag;   // 记录块的访问次数
        bool dirty, valid;  // 是否被修改过和是否有效
        
        // 重载小于
        bool operator< (const Block& t){
            return this->countBlock < t.countBlock;
        }
    };                                                                 
    vector<pair<unsigned, vector<Block>>> cache_set;                    

public:
    Cache(int argc, char* argv[]);     
    void Run();                        
    void Visit(addr loc, char op);     
    void Replace(addr loc, char op);    
    void PrintResult();                
};

#endif
